package edu.lingnan.constroller;

import edu.lingnan.common.Result;
import edu.lingnan.pojo.Product;
import edu.lingnan.service.ProductService;
import edu.lingnan.service.StoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author xBaozi
 * @version 1.0
 * @classname StoreController
 * @description 商家控制器
 * @date 2022/5/27 18:39
 */
@RestController
@RequestMapping("/store")
public class StoreController {

    @Autowired
    private StoreService storeService;

    @Autowired
    private ProductService productService;

    //添加商店商品
    @RequestMapping("/putOnTheShelf")
    public Result putOnTheShelf(Product product) {
        product.setProductStatus(1);
        //添加商品
        Long id = productService.addProduct(product);
        Result result = new Result();
        result.setCode(Result.SUCCESS_CODE);
        product.setId(id);
        result.setData(product);
        result.setMsg("上架成功！");
        return result;
    }



    //下架商品  改变商品状态状态  0下架  1上架
    @RequestMapping("/offTheShelf")
    public Result offTheShelf(Long productId) {
        int status=0;//下架
        productService.updateProductStatus(productId,status);
        Result result = new Result();
        result.setCode(Result.SUCCESS_CODE);
        result.setMsg("下架成功！商品状态已改为0");
        return result;
    }

    //显示店铺商品
    @RequestMapping("/showMyStoreProduct/{storeId}")
    public Result showMyStoreProduct(@PathVariable("storeId") Long storeId) {

        List<Product> productList = productService.selectProductByStoreId(storeId);
        Result result = new Result();
        result.setCode(Result.SUCCESS_CODE);
        result.setData(productList);
        return result;
    }

    //商家信息修改
}
